home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SCI Games E3 2005 Press Kit (USA)
/
SCI Games E3 2005 Press Kit (USA).bin
/
runme_mac.swf
/
scripts
/
__Packages
/
mx
/
controls
/
MediaController.as
< prev
next >
Wrap
Text File
|
2005-05-05
|
25KB
|
771 lines
class mx.controls.MediaController extends mx.core.UIComponent
{
static var symbolName = "MediaController";
static var symbolOwner = mx.controls.MediaController;
var className = "MediaController";
static var version = "2.0.1.78";
var clipParameters = {controllerPolicy:"auto",horizontal:true,activePlayControl:"pause",backgroundStyle:"default"};
static var MINIMUM_HORIZONTAL_WIDTH = 202;
static var CLOSED_HORIZONTAL_HEIGHT = 25;
static var MINIMUM_HORIZONTAL_OPEN_HEIGHT = 63;
static var LOADBAR_HORIZONTAL_CLOSED_Y = 14;
static var LOADBAR_HORIZONTAL_OPEN_Y = 24;
static var MINIMUM_VERTICAL_HEIGHT = 202;
static var CLOSED_VERTICAL_WIDTH = 25;
static var MINIMUM_VERTICAL_OPEN_WIDTH = 80;
static var LOADBAR_VERTICAL_CLOSED_X = 14;
static var MINIPLAYBAR_VERTICAL_CLOSED_X = 8;
static var ANIMATION_TIME = 250;
static var CLOSE_DELAY = 1000;
static var OPEN_DELAY = 100;
static var LOCALIZED_FILE = "streamingmediacontroller.xml";
static var H_BORDER = 8;
static var V_BORDER = 8;
var _animating = false;
var _enabled = true;
function MediaController()
{
super();
}
function get lastProgressMediaType()
{
return this._lastProgressMediaType;
}
function init(Void)
{
mx.controls.streamingmedia.Tracer.trace("MediaController.init: start: policy=" + this._controllerPolicy);
this.initializeParameters();
mx.controls.streamingmedia.Tracer.trace("MediaController.init: after initializeParameters: policy=" + this._controllerPolicy);
var _loc3_ = this._width;
var _loc4_ = this._height;
super.init();
if(this._horizontal)
{
_loc3_ = Math.max(mx.controls.MediaController.MINIMUM_HORIZONTAL_WIDTH,_loc3_);
_loc4_ = Math.max(mx.controls.MediaController.MINIMUM_HORIZONTAL_OPEN_HEIGHT,_loc4_);
}
else
{
_loc3_ = Math.max(mx.controls.MediaController.MINIMUM_VERTICAL_OPEN_WIDTH,_loc3_);
_loc4_ = Math.max(mx.controls.MediaController.MINIMUM_VERTICAL_HEIGHT,_loc4_);
}
this.setSize(_loc3_,_loc4_,true);
mx.controls.streamingmedia.Tracer.trace("MediaController.init: after setSize " + this.__get__width() + "x" + this.__get__height() + " at (" + this._x + "," + this._y + ")");
this._priorPolicy = this._controllerPolicy;
this.createDefaultStrings();
mx.controls.streamingmedia.Tracer.trace("MediaController.init: Initialized properties:");
mx.controls.streamingmedia.Tracer.trace(" controllerPolicy=" + this._controllerPolicy);
mx.controls.streamingmedia.Tracer.trace(" horizontal=" + this._horizontal);
mx.controls.streamingmedia.Tracer.trace(" activePlayControl=" + this._activePlayControl);
mx.controls.streamingmedia.Tracer.trace(" backgroundStyle=" + this._backgroundStyle);
if(this._controllerPolicy == "auto")
{
this._isOpen = false;
this._priorMouseOver = false;
this._closeId = null;
this._openId = null;
Mouse.addListener(this);
this.gotoAndStop(this.getClosedFrameName());
}
else if(this._controllerPolicy == "on")
{
this._isOpen = true;
this.gotoAndStop(this.getOpenFrameName());
}
else if(this._controllerPolicy == "off")
{
this._isOpen = false;
this.gotoAndStop(this.getClosedFrameName());
}
this._isPlaying = this._activePlayControl == "pause";
this._playPercent = 0;
this._playTime = 0;
this._volume = mx.controls.streamingmedia.StreamingMediaConstants.DEFAULT_VOLUME;
this.setOpenUpOrLeft(false);
this.setListeningForPlayheadMoveEvent(true);
this.tabEnabled = false;
this.tabChildren = true;
this.playAtBeginning = false;
this._screenAccommodator = new mx.controls.streamingmedia.ScreenAccommodator(this);
this.redraw(true);
}
function initializeParameters()
{
if(this.__get__horizontal() == null)
{
this.__set__horizontal(true);
}
if(this.__get__controllerPolicy() == null)
{
this.__set__controllerPolicy("auto");
}
if(this.__get__backgroundStyle() == null)
{
this.__set__backgroundStyle("default");
}
if(this.__get__activePlayControl() == null)
{
this.__set__activePlayControl("pause");
}
}
function getOpenFrameName()
{
return !this._horizontal ? "openVertical" : "openHorizontal";
}
function getClosedFrameName()
{
return !this._horizontal ? "closedVertical" : "closedHorizontal";
}
function draw(Void)
{
if(this._isOpen)
{
this.gotoAndStop(this.getOpenFrameName());
this._playBar.draw();
}
else
{
this.gotoAndStop(this.getClosedFrameName());
this._miniPlayBar.draw();
}
this._loadBar.draw();
if(this._horizontal)
{
this.positionControlsHorizontal();
}
else
{
this.positionControlsVertical();
}
this.drawChrome();
}
function positionControlsVertical()
{
if(this._isOpen)
{
this._volumeControl._x = (this.__get__width() - this._volumeControl._width) / 2;
this._volumeControl._y = this.__get__height() - this._volumeControl._height - 8;
this._buttons._x = (this.__get__width() - this._buttons._width) / 2;
this._buttons._y = this.__get__height() - this._buttons._height - this._volumeControl._height - 16;
this._playBar._x = (this.__get__width() - this._playBar._width) / 2;
this._loadBar._x = this._playBar._x + this._playBar._width - 4;
}
else
{
this._loadBar._x = mx.controls.MediaController.LOADBAR_VERTICAL_CLOSED_X;
this._miniPlayBar._x = mx.controls.MediaController.MINIPLAYBAR_VERTICAL_CLOSED_X;
}
}
function positionControlsHorizontal()
{
if(this._isOpen)
{
this._loadBar._y = mx.controls.MediaController.LOADBAR_HORIZONTAL_OPEN_Y;
this._buttons._x = 8;
this._buttons._y = this.__get__height() - this._buttons._height - 8;
this._volumeControl._x = this.__get__width() - this._volumeControl._width - 8;
this._volumeControl._y = this.__get__height() - this._volumeControl._height - 8;
}
else
{
this._loadBar._y = mx.controls.MediaController.LOADBAR_HORIZONTAL_CLOSED_Y;
}
}
function drawChrome(wi, he)
{
if(wi == null)
{
if(this._horizontal)
{
wi = this.width;
}
else
{
wi = !this._isOpen ? mx.controls.MediaController.CLOSED_VERTICAL_WIDTH : this.__get__width();
}
}
if(he == null)
{
if(this._horizontal)
{
he = !this._isOpen ? mx.controls.MediaController.CLOSED_HORIZONTAL_HEIGHT : this.__get__height();
}
else
{
he = this.height;
}
}
this._chrome.visible = this.__get__backgroundStyle() == "default";
this._chrome.showToggles = false;
this._chrome.setSize(wi,he);
this._chrome.draw();
}
function addSecondChrome(theChrome, closedHeight, openHeight, closedWidth, openWidth, fixedEnd)
{
this._secondChrome = theChrome;
this._secondChromeClosedHeight = closedHeight;
this._secondChromeOpenHeight = openHeight;
this._secondChromeClosedWidth = closedWidth;
this._secondChromeOpenWidth = openWidth;
this._secondChromeFixedEnd = fixedEnd;
}
function removeSecondChrome()
{
this._secondChrome = null;
}
function get expanded()
{
return this._isOpen;
}
function onMouseMove()
{
var _loc5_ = _root._xmouse;
var _loc4_ = _root._ymouse;
var _loc3_ = this.hitTest(_loc5_,_loc4_,true);
if(_loc3_ && this._closeId != null || this.isNotAnimating())
{
clearInterval(this._closeId);
this._closeId = null;
}
if(!_loc3_ && this._openId != null || this.isNotAnimating())
{
clearInterval(this._openId);
this._openId = null;
}
if(_loc3_ && !this._isOpen && this._controllerPolicy == "auto" && this._openId == null && !this.isNotAnimating())
{
this._openId = setInterval(this,"expand",mx.controls.MediaController.OPEN_DELAY);
}
else if(!_loc3_ && this._isOpen && this._controllerPolicy == "auto" && this._closeId == null && !this.isNotAnimating())
{
this._closeId = setInterval(this,"contract",mx.controls.MediaController.CLOSE_DELAY);
}
this._priorMouseOver = _loc3_;
}
function expand(force)
{
clearInterval(this._openId);
this._openId = null;
if(this._controllerPolicy == "auto" || force)
{
this._isOpen = true;
this._animationStart = getTimer();
this._animationOpen = true;
this._priorMouseOver = true;
this.onEnterFrame = this.animate;
}
}
function contract(force)
{
mx.controls.streamingmedia.Tracer.trace("MediaController.contract: force=" + force + ", animating=" + this._animating + ", opening=" + this._animationOpen);
if(this._animating && !this._animationOpen)
{
return undefined;
}
clearInterval(this._closeId);
this._closeId = null;
if(this._controllerPolicy == "auto" || force)
{
this._isOpen = false;
this._animationStart = getTimer();
this._animationOpen = false;
this._priorMouseOver = false;
this.gotoAndStop(this.getClosedFrameName());
this.animate();
this.onEnterFrame = this.animate;
}
}
function animate()
{
this._animating = true;
var _loc4_ = getTimer() - this._animationStart;
var _loc3_ = Math.min(1,_loc4_ / mx.controls.MediaController.ANIMATION_TIME);
mx.controls.streamingmedia.Tracer.trace("MediaController.animate: _animationStart=" + this._animationStart + ", elapsed=" + _loc4_ + ", portion=" + _loc3_ + ", ANIMATION_TIME=" + mx.controls.MediaController.ANIMATION_TIME);
this.sizeMainChrome(_loc3_);
if(this._secondChrome != null)
{
this.sizeSecondChrome(_loc3_);
}
this.animateBars(_loc3_);
if(_loc4_ >= mx.controls.MediaController.ANIMATION_TIME || _global.isLivePreview)
{
this.animationDone();
}
}
function animationDone()
{
mx.controls.streamingmedia.Tracer.trace("MediaController.animationDone");
this._animating = false;
delete this.onEnterFrame;
this.refreshBars();
if(this._animationOpen)
{
this.gotoAndStop(this.getOpenFrameName());
}
this.redraw(true);
}
function sizeMainChrome(portion)
{
var _loc2_ = this.__get__height();
var _loc3_ = this.__get__width();
if(this._horizontal)
{
var _loc4_ = (this.__get__height() - mx.controls.MediaController.CLOSED_HORIZONTAL_HEIGHT) * portion;
if(this._animationOpen)
{
_loc2_ = mx.controls.MediaController.CLOSED_HORIZONTAL_HEIGHT + _loc4_;
}
else
{
_loc2_ = this.__get__height() - _loc4_;
}
}
else
{
_loc4_ = (this.__get__width() - mx.controls.MediaController.CLOSED_VERTICAL_WIDTH) * portion;
if(this._animationOpen)
{
_loc3_ = mx.controls.MediaController.CLOSED_VERTICAL_WIDTH + _loc4_;
}
else
{
_loc3_ = this.__get__width() - _loc4_;
}
}
if(this.isOpenUpOrLeft())
{
var _loc6_ = this._chrome.width - _loc3_;
var _loc5_ = this._chrome.height - _loc2_;
this._x += _loc6_;
this._y += _loc5_;
}
this.drawChrome(_loc3_,_loc2_);
}
function sizeSecondChrome(portion)
{
var _loc3_ = undefined;
var _loc4_ = undefined;
var _loc2_ = undefined;
if(this._horizontal)
{
_loc4_ = this._secondChromeClosedWidth;
_loc2_ = (this._secondChromeOpenHeight - this._secondChromeClosedHeight) * portion;
_loc3_ = !this._animationOpen ? this._secondChromeOpenHeight - _loc2_ : this._secondChromeClosedHeight + _loc2_;
if(this._secondChromeFixedEnd)
{
this._secondChrome._y = this._secondChrome._y - _loc3_ + this._secondChrome.height;
}
}
else
{
_loc3_ = this._secondChromeClosedHeight;
_loc2_ = (this._secondChromeOpenWidth - this._secondChromeClosedWidth) * portion;
_loc4_ = !this._animationOpen ? this._secondChromeOpenWidth - _loc2_ : this._secondChromeClosedWidth + _loc2_;
if(this._secondChromeFixedEnd)
{
this._secondChrome._x = this._secondChrome._x - _loc4_ + this._secondChrome.width;
}
}
this._secondChrome.setSize(_loc4_,_loc3_);
this._secondChrome.draw();
}
function animateBars(portion)
{
var _loc2_ = undefined;
if(this._horizontal)
{
_loc2_ = (mx.controls.MediaController.LOADBAR_HORIZONTAL_OPEN_Y - mx.controls.MediaController.LOADBAR_HORIZONTAL_CLOSED_Y) * portion;
var _loc8_ = !this._animationOpen ? mx.controls.MediaController.LOADBAR_HORIZONTAL_OPEN_Y - _loc2_ : mx.controls.MediaController.LOADBAR_HORIZONTAL_CLOSED_Y + _loc2_;
this._loadBar._y = _loc8_;
}
else
{
var _loc5_ = this._chrome.width / 2;
_loc2_ = (_loc5_ - mx.controls.MediaController.MINIPLAYBAR_VERTICAL_CLOSED_X) * portion;
_loc2_ = Math.max(0,_loc2_);
var _loc9_ = !this._animationOpen ? _loc5_ - _loc2_ : mx.controls.MediaController.MINIPLAYBAR_VERTICAL_CLOSED_X + _loc2_;
this._miniPlayBar._x = _loc9_;
this._loadBar._x = this._miniPlayBar._x + this._miniPlayBar._width;
var _loc3_ = this._loadBar.getClosedHeight();
var _loc4_ = this._loadBar.getOpenHeight();
_loc2_ = (_loc3_ - _loc4_) * portion;
var _loc6_ = !this._animationOpen ? _loc4_ + _loc2_ : _loc3_ - _loc2_;
this._loadBar.draw(_loc6_);
this._miniPlayBar.draw(_loc6_);
}
}
function getLoadBar()
{
return this._loadBar;
}
function refreshBars()
{
mx.controls.streamingmedia.Tracer.trace("MediaController.refreshBars: load=" + this._loadPercent + ", play=" + this._playPercent);
this._loadBar.setCompletionPercentage(this._loadPercent);
this._playBar.setCompletionPercentage(this._playPercent);
this._miniPlayBar.setCompletionPercentage(this._playPercent);
}
function getLoadPercent()
{
return this._loadPercent;
}
function getMinimumOpenHeight()
{
var _loc2_ = !this._horizontal ? mx.controls.MediaController.MINIMUM_VERTICAL_HEIGHT : mx.controls.MediaController.MINIMUM_HORIZONTAL_OPEN_HEIGHT;
return _loc2_;
}
function getMinimumClosedHeight()
{
var _loc2_ = !this._horizontal ? mx.controls.MediaController.MINIMUM_VERTICAL_HEIGHT : mx.controls.MediaController.CLOSED_HORIZONTAL_HEIGHT;
return _loc2_;
}
function getMinimumOpenWidth()
{
var _loc2_ = !this._horizontal ? mx.controls.MediaController.MINIMUM_VERTICAL_OPEN_WIDTH : mx.controls.MediaController.MINIMUM_HORIZONTAL_WIDTH;
return _loc2_;
}
function getMinimumClosedWidth()
{
var _loc2_ = !this._horizontal ? mx.controls.MediaController.CLOSED_VERTICAL_WIDTH : mx.controls.MediaController.MINIMUM_HORIZONTAL_WIDTH;
return _loc2_;
}
function get controllerPolicy()
{
return this._controllerPolicy;
}
function set controllerPolicy(aPolicy)
{
mx.controls.streamingmedia.Tracer.trace("MediaController.set controllerPolicy: old=" + this._controllerPolicy + ", new=" + aPolicy);
if(aPolicy == this._controllerPolicy)
{
return undefined;
}
this._controllerPolicy = aPolicy;
if(this._controllerPolicy == "on")
{
Mouse.removeListener(this);
if(!this._isOpen)
{
this.expand(true);
}
}
else if(this._controllerPolicy == "off")
{
Mouse.removeListener(this);
if(this._isOpen)
{
mx.controls.streamingmedia.Tracer.trace("MediaController.set controllerPolicy(off): about to call contract");
this.contract(true);
}
}
else if(this._controllerPolicy == "auto")
{
this._closeId = null;
this._openId = null;
Mouse.addListener(this);
var _loc3_ = this.hitTest(_root._xmouse,_root._ymouse,true);
if(this._isOpen && !_loc3_)
{
mx.controls.streamingmedia.Tracer.trace("MediaController.set controllerPolicy(auto): about to call contract");
this.contract();
}
else if(!this._isOpen && _loc3_)
{
this.expand();
}
}
}
function get horizontal()
{
return this._horizontal;
}
function set horizontal(isHoriz)
{
if(isHoriz != this._horizontal)
{
this._horizontal = isHoriz;
var _loc2_ = this.__get__height();
var _loc3_ = this.__get__width();
if(isHoriz)
{
_loc2_ = Math.max(_loc2_,mx.controls.MediaController.MINIMUM_HORIZONTAL_WIDTH);
_loc3_ = Math.max(_loc3_,mx.controls.MediaController.MINIMUM_HORIZONTAL_OPEN_HEIGHT);
}
else
{
_loc2_ = Math.max(_loc2_,mx.controls.MediaController.MINIMUM_VERTICAL_OPEN_WIDTH);
_loc3_ = Math.max(_loc3_,mx.controls.MediaController.MINIMUM_VERTICAL_HEIGHT);
}
this.setSize(_loc2_,_loc3_);
this.invalidate();
}
else
{
this._horizontal = isHoriz;
}
}
function get volume()
{
return this._volume;
}
function set volume(vol)
{
this._volume = vol;
this._volumeControl.getHandle().setVolume(vol);
}
function get backgroundStyle()
{
return this._backgroundStyle;
}
function set backgroundStyle(aStyle)
{
this._backgroundStyle = aStyle;
this.drawChrome();
}
function broadcastEvent(eventType, detailArg)
{
var _loc2_ = {type:eventType,target:this,detail:detailArg};
if(eventType == "volume")
{
this._volume = detailArg;
}
this.dispatchEvent(_loc2_);
}
function handleEvent(ev)
{
if(ev.type == "change")
{
this.playAtBeginning = false;
if(this.isListeningForPlayheadMoveEvent())
{
this.handleChangeEvent(ev);
}
}
else if(ev.type == "progress")
{
this.handleProgressEvent(ev);
}
else if(ev.type == "complete")
{
this.handleCompleteEvent(ev);
}
else if(ev.type == "scrubbing")
{
this.handleScrubbingEvent(ev);
}
else
{
this.handleUnrecognizedEvent(ev);
}
}
function isListeningForPlayheadMoveEvent()
{
return this._listenForPlayheadMoveEvent;
}
function setListeningForPlayheadMoveEvent(listen)
{
this._listenForPlayheadMoveEvent = listen;
}
function isNotAnimating()
{
return this._notAnimating;
}
function setNotAnimating(still)
{
this._notAnimating = still;
}
function get activePlayControl()
{
return this._activePlayControl;
}
function set activePlayControl(aControl)
{
this._activePlayControl = aControl;
}
function get playing()
{
return this.isPlaying();
}
function set playing(playFlag)
{
this.setPlaying(playFlag);
}
function isPlaying()
{
return this._isPlaying;
}
function setPlaying(playFlag)
{
this._isPlaying = playFlag;
this._playBar.setIsPlaying(playFlag);
if(playFlag)
{
this._buttons.playPauseButtons.showPauseButton();
}
else
{
this._buttons.playPauseButtons.showPlayButton();
}
}
function handleChangeEvent(ev)
{
var _loc2_ = ev.target;
this._playTime = _loc2_.playheadTime;
var _loc3_ = _loc2_.__get__totalTime();
this._playPercent = 100 * this._playTime / _loc3_;
if(this._isOpen)
{
this._playBar.setCompletionPercentage(this._playPercent);
this._playBar.setTime(this._playTime);
}
else
{
this._miniPlayBar.setCompletionPercentage(this._playPercent);
}
}
function handleProgressEvent(ev)
{
if(ev.target.isRtmp(ev.target.contentPath))
{
this._loadPercent = 100;
}
else
{
var _loc4_ = ev.target.bytesLoaded;
var _loc3_ = ev.target.bytesTotal;
this._loadPercent = 100 * _loc4_ / _loc3_;
}
this.refreshBars();
this._lastProgressMediaType = ev.target.mediaType;
this.evaluateToEnd();
}
function evaluateToEnd()
{
if(!this._isOpen)
{
return undefined;
}
var _loc2_ = false;
if(this._loadPercent >= 99 && this.__get__enabled())
{
if(this._lastProgressMediaType == "MP3")
{
_loc2_ = true;
}
else if(this._lastProgressMediaType == "FLV" && !mx.controls.streamingmedia.StreamingMediaConstants.DISABLE_FLV_TOEND)
{
_loc2_ = true;
}
}
this._buttons.toEndButton.enabled = _loc2_;
}
function handleCompleteEvent(ev)
{
if(!this.isScrubbing() && !this._animating)
{
var _loc2_ = ev.target;
this._playTime = _loc2_.totalTime;
this._playPercent = 100;
if(this._isOpen)
{
this._playBar.setCompletionPercentage(this._playPercent);
this._playBar.setTime(this._playTime);
}
else
{
this._miniPlayBar.setCompletionPercentage(this._playPercent);
}
this.setPlaying(false);
mx.controls.streamingmedia.Tracer.trace("MediaController.handleCompleteEvent: playAtBeginning=true");
this.playAtBeginning = true;
}
}
function handleScrubbingEvent(ev)
{
this._listenForPlayheadMoveEvent = !ev.detail;
}
function handleUnrecognizedEvent(ev)
{
mx.controls.streamingmedia.Tracer.trace("received an unrecognized event of type " + ev.type + " with target " + ev.target);
}
function createDefaultStrings()
{
this._strings = new Object();
this._strings.paused = "PAUSED";
this._strings.streaming = "STREAMING";
}
function getLocalizedString(id)
{
var _loc2_ = this._strings[id];
return _loc2_;
}
function get playTime()
{
return this._playTime;
}
function set playTime(aTime)
{
this._playTime = aTime;
}
function get playPercent()
{
return this._playPercent;
}
function set playPercent(aPercent)
{
this._playPercent = aPercent;
}
function isOpenUpOrLeft()
{
return this._openUpOrLeft;
}
function setOpenUpOrLeft(is)
{
this._openUpOrLeft = is;
}
function associateDisplay(d)
{
d.associateController(this);
}
function setSize(w, h, noEvent)
{
super.setSize(w,h,noEvent);
this.invalidate();
}
function get enabled()
{
return this._enabled;
}
function set enabled(is)
{
mx.controls.streamingmedia.Tracer.trace("MediaController.set enabled to " + is);
this._enabled = is;
this._buttons.toStartButton.enabled = is;
this._buttons.toEndButton.enabled = is;
this._buttons.playPauseButtons.enabled = is;
this._volumeControl._muteButton.muteSimpleButton.enabled = is;
this._volumeControl._loudButton.loudSimpleButton.enabled = is;
this._playBar.__set__enabled(is);
this._volumeControl.getHandle().__set__enabled(is);
if(is)
{
if(this._priorPolicy != null)
{
this.__set__controllerPolicy(this._priorPolicy);
}
}
else
{
this._priorPolicy = this.controllerPolicy;
if(this.__get__controllerPolicy() == "auto")
{
this.__set__controllerPolicy("off");
}
}
}
function isScrubbing()
{
return this._playBar.isScrubbing();
}
}